package com.amap.map2d.demo.overlay;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.amap.map2d.demo.AdminActivity;
import com.amap.map2d.demo.MainActivity;
import com.amap.map2d.demo.R;
import com.amap.map2d.demo.util.SQLiteDbHelper;

public class LoginActivity extends Activity {

    private EditText userEdit, pwdEdit;
    private Button login;
    private final String name = "admin";

    private final String pwd = "123456";
    private final String admin_pwd = "admin";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        initView();
        initDb();
    }

    public void initView() {
        userEdit = findViewById(R.id.et_userName);
        pwdEdit = findViewById(R.id.et_password);
        login = findViewById(R.id.btn_login);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (name.equals(userEdit.getText().toString()) && pwd.equals(pwdEdit.getText().toString())) {
                    Intent intent = new Intent();
                    intent.setClass(getApplicationContext(), MainActivity.class);
                    startActivity(intent);
                    finish();
                } else if (name.equals(userEdit.getText().toString()) && admin_pwd.equals(pwdEdit.getText().toString())) {
                    Intent intent = new Intent();
                    intent.setClass(getApplicationContext(), AdminActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_LONG).show();
                }

            }
        });
    }

    public void initDb() {
        SQLiteDbHelper helper = new SQLiteDbHelper(getApplicationContext());
        SQLiteDatabase database = helper.getWritableDatabase();

    }
}
